home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 234_01 / xdir.c < prev    next >
Text File  |  1987-06-16  |  18KB  |  700 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     XDIR - Hard Disk Manager
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      Apr 03, 1987
  6.   DESCRIPTION:     Hard Disk Manager for IBM PC
  7.   KEYWORDS:     Hard Disk Manager Dump Directory
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      xdir.C
  10.   WARNINGS:     None
  11.   CRC:         N/A
  12.   SEE-ALSO:     HDIR.DOC and XDIR.DOC
  13.   AUTHOR:     Mike Blakley 15645 SW 82 Cir Ln #76, Miami, Fl 33193
  14.   COMPILERS:     ECO-C
  15.   REFERENCES:     XDIR.DOC
  16. */
  17.  
  18.  
  19. /*
  20.    xdir.c
  21.    Superwash
  22.    to process the DOS directories
  23.  
  24. */
  25. #include "hdir.doc"          /* program documentation */
  26. #include "stdio.h"
  27. #include "dos.h"
  28. #include "dir.h"
  29. #include "xdir.h"
  30. struct tdir *pnam[MAXDIR];   /* directory entries */
  31. struct tdir *fnam[MAXFILE];  /* file names */
  32.  
  33. char  cdir[PATHSIZ];     /* current directory */
  34. char  helpfile[PATHSIZ] = "xdir.doc";      /* name of helpfile */
  35. unsigned cdate;          /* comparison date */
  36. /*
  37.   process DOS directories
  38.  
  39. */
  40. main(argc,argv)
  41. int  argc;     /* argument count */
  42. char **argv;   /* argument values */
  43. {
  44.      int    strcmp(char *,char *);
  45.      void   dironly(char **buffer, int type,int level);
  46.      void   update (char **buffer, int type,int level);
  47.      char   *strdsave(struct direct *, char *root);
  48.  
  49.      char   *alloc(int amt);
  50.      int    i,j;
  51.      char   answer[MAXFILE];      /* for responses */
  52.      char   srmask[15];           /* search mask */
  53.      int    att;                  /* attribute search */
  54.      struct tdir *tp;
  55.      static int pcount, fcount;
  56.      int    cf,ct;                /* flag for see files */
  57.      char   work[20];             /* work area selected dir */
  58.      static int firstime = 0;    /* for command line directory */
  59.      char   c,temp[20];             /* debug */
  60.  
  61.  
  62.      if (argc == 2)             /* process command line args */
  63.       {
  64.       if (strcmp(argv[1],"help") == 0) typ(helpfile);
  65.       if (strcmp(argv[1],"-v")   == 0) ;
  66.       }
  67.      else if (argc == 1)
  68.       {
  69.       i = help();               /* display help message */
  70.       if (i == 1) typ(helpfile);
  71.       }
  72.  
  73.      pcount = bildir();                   /* build path array */
  74.      qksort(pcount,pcomp,pswap);          /* sort by path name */
  75.  
  76.      if (argc == 2)                       /* test command line directory */
  77.      {
  78.      strcpy(work,argv[1]);
  79.      j = testdir(work,pcount);
  80.      if (j < 0) firstime = 0;
  81.         else
  82.          {
  83.          firstime = 1;
  84.          strcpy(cdir,work);
  85.          clear(answer,MAXFILE,' ');
  86.          answer[j] = 'S';
  87.          }
  88.      }
  89.  
  90.  
  91.      while (1)                         /* main loop */
  92.      {
  93.  
  94.      if (firstime)   firstime = 0;
  95.          else
  96.          {
  97.          clear(answer,MAXFILE,' ');   /* clear answers */
  98.          disx(pnam,pcount,answer,1); /* ask what directory  <=== */
  99.          }
  100.  
  101.      for (i=ct=0;i<MAXFILE;i++)        /* get directory selection */
  102.      {
  103.      if (answer[i] == 'S')   /* selection criteria */
  104.         {
  105.         ++ct;
  106.         tp = pnam[i];
  107.         strcpy(cdir,tp->d_name);       /* note current directory */
  108.         if (cdir[0] == 0) strcpy(cdir,"**ROOT**");
  109.         break;
  110.         }
  111.      }
  112.  
  113.      if (ct == 0) break;                 /* nothing selected */
  114.  
  115.      while (1)                           /* get search criteria */
  116.      {
  117.      j = criteria(srmask,&att,&cf);
  118.      if (j) break;
  119.      }
  120.  
  121.      fcount = bilfil(pnam[i],srmask,cdate,att); /* build file names array */
  122.      if (fcount == 0)
  123.         {
  124.         xmsg("No entries selected - press any key ");
  125.         continue;
  126.         }
  127.  
  128.      if (fcount == -1)
  129.         {
  130.         xmsg("Couldn't allocate memory ");
  131.         break;
  132.         }
  133.  
  134.      switch (cf)    /* determine sort method */
  135.      {
  136.      case 'D':
  137.        qksort(fcount,fcompd,fswap);
  138.        break;
  139.      case 'S':
  140.        qksort(fcount,fcomps,fswap);
  141.        break;
  142.      default:
  143.        qksort(fcount,fcomp,fswap);     /* sort alpha on file names */
  144.        break;
  145.      }
  146.  
  147.      if ((cf == 'Y') || (cf == 'D') || (cf == 'S') || (cf == 'A'))
  148.           dfnam(fcount,cdir);    /* display files */
  149.  
  150.      clear(answer,MAXFILE,' ');
  151.      disx(fnam,fcount,answer,2);   /* ask what files */
  152.      for (i=ct=0;i<MAXFILE;i++)    /* count responses */
  153.         if (answer[i] != ' ') ++ct;
  154.  
  155.      if (ct) action(answer,pcount);    /* process answer */
  156.      for (i=0;i<fcount;i++) free(fnam[i]);  /* free storage */
  157.  
  158.      clrscr();
  159.      cursor(5,10);
  160.      writestr("Processing completed - enter next directory name ");
  161.      cursor(6,10);
  162.      writestr("Press ENTER for root directory, ESC to end ");
  163.      c = getch();
  164.      if (c == 27) break;
  165.      if (c == 13) work[0] = 0;
  166.         else
  167.         {
  168.         putchar(c);
  169.         gets(temp);
  170.         work[0] = c;
  171.         work[1] = 0;
  172.         strcat(work,temp);
  173.         }
  174.  
  175.      j = testdir(work,pcount);
  176.      if (j < 0) firstime = 0;
  177.         else
  178.          {
  179.          firstime = 1;
  180.          strcpy(cdir,work);
  181.          clear(answer,MAXFILE,' ');
  182.          answer[j] = 'S';
  183.          }
  184.  
  185.      }   /* end while 1 processing */
  186.      clrscr();
  187. }
  188.  
  189. /*
  190.   action
  191.   take the requested action
  192. */
  193. void action(answer,pcount)
  194. char *answer;
  195. int  pcount;
  196. {
  197.  
  198.      static int  i,j,k,l,c;
  199.      int    rc;                 /* return code from delete */
  200.      char filename[80];         /* used in rename and copy */
  201.      struct tdir *tp, *fp;
  202.      int  row;
  203.      char key[30];              /* encryption key */
  204.      static int dflag;          /* flag for display */
  205.      int copybulk = 0;          /* no bulk copy */
  206.      char bulkname[80];         /* bulk file name */
  207.      int found;                 /* found flag for search of paths */
  208.      char workname[80];         /* work area for file name */
  209.  
  210.      dflag = 1;                 /* indicate need for screen display */
  211.  
  212.      for (i=0;i<MAXFILE;i++)
  213.      {
  214.      tp = fnam[i];
  215.      j = (int) answer[i];
  216.  
  217.      switch (j)
  218.      {
  219.      case 'T':                  /* list a file to console */
  220.        typ(tp->d_path);
  221.        dflag = 1;               /* indicate new display required */
  222.        break;
  223.      case 'L':                  /* list file to printer */
  224.        clrscr();
  225.        writestr("    File ");
  226.        writestr(tp->d_path);
  227.        writestr(" will be listed to the printer ");
  228.        lis(tp->d_path);
  229.        break;
  230.      case 'C':                  /* copy file */
  231.        if (copybulk)   /* bulk copy no questions */
  232.           {
  233.           strcpy(filename,bulkname);
  234.           strcat(filename,"\\");
  235.           strcat(filename,tp->d_name);
  236.           xcopy(tp->d_path,filename);
  237.           break;
  238.           }
  239.  
  240.           dscr();         /* display the screen */
  241.           row = 4;
  242.           cursor(row++,20);
  243.           writestr("Copy from file ");
  244.           writestr(tp->d_path);
  245.           writestr(" to ? ");
  246.           gets(filename);
  247.           if (strlen(filename) == 0) break;
  248.           for (l=0,k=strlen(filename);l<k;l++)
  249.               filename[l] = toupper(filename[l]);
  250.  
  251.           if (filename[0] != '\\')
  252.              {
  253.              cvp(tp->d_path,workname);
  254.              strcat(workname,"\\");
  255.              strcat(workname,filename);
  256.              strcpy(filename,workname);  /* build output name */
  257.              }
  258.  
  259.           else
  260.           {
  261.           for (l=found=0;l<pcount;l++)   /* see if a path */
  262.             {
  263.             fp = pnam[l];
  264.             k = strcmp(fp->d_path,filename);
  265.             if (k == 0) found = 1;
  266.             }
  267.  
  268.           if (found == 1)
  269.              {
  270.              cursor(row++,20);
  271.              writestr("Desire bulk copy? (Y)es (N)o ");
  272.              c = toupper(getch());
  273.              if (c == 'Y')
  274.                 {
  275.                 copybulk = 1;
  276.                 strcpy(bulkname,filename);
  277.                 strcat(filename,"\\");
  278.                 strcat(filename,tp->d_name);
  279.                 xcopy(tp->d_path,filename);
  280.                 }
  281.              }
  282.  
  283.            }
  284.  
  285.            xcopy(tp->d_path,filename);     /* copy the file */
  286.  
  287.        break;
  288.      case 'R':         /* rename the file */
  289.        dscr();         /* display t